package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.advert.AdvertAddVo;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.advert.AdvertInfoVo;
import com.cskaoyan.bean.po.MarketAd;
import com.cskaoyan.service.AdvertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
 * @author LiangRuiJiang
 * @since 2022/06/05  14:09
 */
@RestController
@RequestMapping("admin/ad")
public class AdvertController {

    @Autowired
    AdvertService advertService;

    @RequestMapping("list")
    public BaseRespVo list(BaseParam baseParam,String name,String content){

        AdvertInfoVo advertInfoVo = advertService.queryAdvert(baseParam,name,content);
        return BaseRespVo.ok(advertInfoVo);
    }

    @RequestMapping(value = "create",method = RequestMethod.POST)
    public BaseRespVo create(@RequestBody() MarketAd marketAd){

        AdvertAddVo data = advertService.createAdvert(marketAd);
        return BaseRespVo.ok(data);
    }

    /**
     * 广告信息的编辑
     * @param marketAd
     * @return
     */
    @RequestMapping(value = "update",method = RequestMethod.POST)
    public BaseRespVo update(@RequestBody() MarketAd marketAd){
        MarketAd marketAdNew = advertService.updateAdvert(marketAd);
        return BaseRespVo.ok(marketAdNew);
    }

    /**
     * 广告信息的逻辑删除
     * @param marketAd
     * @return
     */
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    public BaseRespVo delete(@RequestBody() MarketAd marketAd){
        MarketAd marketAdNew = advertService.updateAdvert(marketAd);
        return BaseRespVo.ok();
    }

}
